package com.clone.surpassli.clone_cloudreader.utils;

import android.view.View;

/**
 * 避免在一秒内触发多次点击
 * Created by SurpassLi on 2017/9/29.
 * PerfectClickListener
 */
public abstract class PerfectClickListener implements View.OnClickListener{

    private static final int MIN_CLICK_DELAY_TIME = 1000;
    private long mLastClickTime = 0;
    private int mId = -1;

    @Override
    public void onClick(View view) {
       long currentTime = System.currentTimeMillis();;
       int id = view.getId();
        if (id != mId) {
            mId = id;
            mLastClickTime = currentTime;
            onNoDoubleClick(view);
            return;
        }
        if (currentTime - mLastClickTime > MIN_CLICK_DELAY_TIME){
            mLastClickTime = currentTime;
            onNoDoubleClick(view);
        }
    }

    protected abstract void onNoDoubleClick(View v);
}
